/**
 * @class Index
 * @fileOverview 首页控制器
 * @extends yijs.air.Controller
 */ 
var Index = function(){
	//加载用户模型
	this.ModelUser =  new User();
	//获取自动登录用户
	this.autoLoginData = this.ModelUser.getAutoLogin();
	if(this.autoLoginData != null && this.autoLoginData.length > 0){
		this.runBlogController();
	}else{
		this.runLoginController();
	}
}
/**
 * 运行微博控制器
 */
Index.prototype.runBlogController = function(){
		var name       = Base64.decode(this.autoLoginData[0].name);
		var password   = Base64.decode(this.autoLoginData[0].password);
		var controller = this.autoLoginData[0].controller;
		var user = {name:name,password:password,controller:controller};
		var Blog       = helpYi.getController(controller,user);
		Blog.view();	
}
/**
 * 运行登录控制器
 */
Index.prototype.runLoginController = function(){
		var oLogin = new Login();
		oLogin.bind("submit",function(evt){
			var data            = evt.data;
			var authorization   = data.authorization;
			var Base64_USERNAME = Base64.encode(data.name);
			var Base64_PASSWORD = Base64.encode(data.password);
			var controller      = data.controller;
			var autoLogin       = data.autoLogin;
			var isRemember      = data.isRemember		
			//获取指定控制器，触发身份认证			
			var Blog            = helpYi.getController(data.controller);
			Blog.verify(function(data){
				var _authorizedField = Blog.field.authorized;
				var _bool = Boolean($(data).find(_authorizedField).text());
				if(_bool){
					helpYi.preLoad.msg(yijs.lang.login.success);
					var data = {name : Base64_USERNAME,password : Base64_PASSWORD,controller:controller,autoLogin:autoLogin,isRemember:isRemember};
					oLogin.model.insert(data);						
					helpYi.preLoad.hide(500,function(){
						Blog.view();
					});
					
				}else{
					alert(yijs.lang.login.errors.loginFail);
				}											
			});
		})		
}
